package com.chaofan.authsso.client.properties;

import cn.hutool.core.util.StrUtil;
import com.chaofan.authsso.client.common.Constant;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * authsso配置实体类
 * Author: Chaofan
 * Date: 2020/6/4 14:25
 * email: chaofan2685@qq.com
 */
@ConfigurationProperties("authsso.client")
public class SsoRegisterProperties {

    //单点登录中心端地址,用于后端向服务端发送接口请求申请token,校验token等
    private String host;

    //单点登录中心端页面跳转地址,用于在申请到token和验证码后,将验证码拼接成跳转地址时使用,默认情况下与host相同,如果host配置的地址是远程服务器的内网地址,很可能造成前端无法正常跳转,因此这里可以配置远程服务器的公网地址
    private String frontHost;

    //定义的需要登录验证的接口（eg:/api/*）
    private List<String> loginCheck = new ArrayList<>();

    //接口白名单
    private List<String> whitelist = new ArrayList<>();

    //存入session的token的key
    private String tokenName = Constant.DEFAULT_TOKEN_NAME;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public List<String> getLoginCheck() {
        return loginCheck;
    }

    public void setLoginCheck(List<String> loginCheck) {
        this.loginCheck = loginCheck;
    }

    public List<String> getWhitelist() {
        return whitelist;
    }

    public void setWhitelist(List<String> whitelist) {
        this.whitelist = whitelist;
    }

    public String getTokenName() {
        return tokenName;
    }

    public void setTokenName(String tokenName) {
        if (StrUtil.isNotEmpty(tokenName)){
            this.tokenName = tokenName;
        }
    }

    public String getFrontHost() {
        if (StrUtil.isNotEmpty(frontHost)){
            return frontHost;
        }else {
            return host;
        }
    }

    public void setFrontHost(String frontHost) {
        this.frontHost = frontHost;
    }
}
